<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class StringScanner - strscan: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-StringScanner-label-Method+Categories">Method Categories</a>
    <li><a href="#class-StringScanner-label-Advancing+the+Scan+Pointer">Advancing the Scan Pointer</a>
    <li><a href="#class-StringScanner-label-Looking+Ahead">Looking Ahead</a>
    <li><a href="#class-StringScanner-label-Finding+Where+we+Are">Finding Where we Are</a>
    <li><a href="#class-StringScanner-label-Setting+Where+we+Are">Setting Where we Are</a>
    <li><a href="#class-StringScanner-label-Match+Data">Match Data</a>
    <li><a href="#class-StringScanner-label-Miscellaneous">Miscellaneous</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-must_C_version">::must_C_version</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-3C-3C">#&lt;&lt;</a>
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-beginning_of_line-3F">#beginning_of_line?</a>
    <li ><a href="#method-i-captures">#captures</a>
    <li ><a href="#method-i-charpos">#charpos</a>
    <li ><a href="#method-i-check">#check</a>
    <li ><a href="#method-i-check_until">#check_until</a>
    <li ><a href="#method-i-clear">#clear</a>
    <li ><a href="#method-i-concat">#concat</a>
    <li ><a href="#method-i-empty-3F">#empty?</a>
    <li ><a href="#method-i-eos-3F">#eos?</a>
    <li ><a href="#method-i-exist-3F">#exist?</a>
    <li ><a href="#method-i-fixed_anchor-3F">#fixed_anchor?</a>
    <li ><a href="#method-i-get_byte">#get_byte</a>
    <li ><a href="#method-i-getbyte">#getbyte</a>
    <li ><a href="#method-i-getch">#getch</a>
    <li ><a href="#method-i-initialize_copy">#initialize_copy</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-match-3F">#match?</a>
    <li ><a href="#method-i-matched">#matched</a>
    <li ><a href="#method-i-matched-3F">#matched?</a>
    <li ><a href="#method-i-matched_size">#matched_size</a>
    <li ><a href="#method-i-named_captures">#named_captures</a>
    <li ><a href="#method-i-peek">#peek</a>
    <li ><a href="#method-i-peep">#peep</a>
    <li ><a href="#method-i-pointer">#pointer</a>
    <li ><a href="#method-i-pointer-3D">#pointer=</a>
    <li ><a href="#method-i-pos">#pos</a>
    <li ><a href="#method-i-pos-3D">#pos=</a>
    <li ><a href="#method-i-post_match">#post_match</a>
    <li ><a href="#method-i-pre_match">#pre_match</a>
    <li ><a href="#method-i-reset">#reset</a>
    <li ><a href="#method-i-rest">#rest</a>
    <li ><a href="#method-i-rest-3F">#rest?</a>
    <li ><a href="#method-i-rest_size">#rest_size</a>
    <li ><a href="#method-i-restsize">#restsize</a>
    <li ><a href="#method-i-scan">#scan</a>
    <li ><a href="#method-i-scan_full">#scan_full</a>
    <li ><a href="#method-i-scan_until">#scan_until</a>
    <li ><a href="#method-i-search_full">#search_full</a>
    <li ><a href="#method-i-size">#size</a>
    <li ><a href="#method-i-skip">#skip</a>
    <li ><a href="#method-i-skip_until">#skip_until</a>
    <li ><a href="#method-i-string">#string</a>
    <li ><a href="#method-i-string-3D">#string=</a>
    <li ><a href="#method-i-terminate">#terminate</a>
    <li ><a href="#method-i-unscan">#unscan</a>
    <li ><a href="#method-i-values_at">#values_at</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-StringScanner">
    <h1 id="class-StringScanner" class="class">
      class StringScanner
    </h1>

    <section class="description">
    
<p><a href="StringScanner.html"><code>StringScanner</code></a> provides for lexical scanning operations on a String.  Here is an example of its usage:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;strscan&#39;</span>

<span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;This is an example string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">eos?</span>               <span class="ruby-comment"># -&gt; false</span>

<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)      <span class="ruby-comment"># -&gt; &quot;This&quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)      <span class="ruby-comment"># -&gt; nil</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\s+/</span>)      <span class="ruby-comment"># -&gt; &quot; &quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\s+/</span>)      <span class="ruby-comment"># -&gt; nil</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)      <span class="ruby-comment"># -&gt; &quot;is&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">eos?</span>               <span class="ruby-comment"># -&gt; false</span>

<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\s+/</span>)      <span class="ruby-comment"># -&gt; &quot; &quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)      <span class="ruby-comment"># -&gt; &quot;an&quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\s+/</span>)      <span class="ruby-comment"># -&gt; &quot; &quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)      <span class="ruby-comment"># -&gt; &quot;example&quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\s+/</span>)      <span class="ruby-comment"># -&gt; &quot; &quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)      <span class="ruby-comment"># -&gt; &quot;string&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">eos?</span>               <span class="ruby-comment"># -&gt; true</span>

<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\s+/</span>)      <span class="ruby-comment"># -&gt; nil</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)      <span class="ruby-comment"># -&gt; nil</span>
</pre>

<p>Scanning a string means remembering the position of a <em>scan pointer</em>, which is just an index.  The point of scanning is to move forward a bit at a time, so matches are sought after the scan pointer; usually immediately after it.</p>

<p>Given the string “test string”, here are the pertinent scan pointer positions:</p>

<pre>  t e s t   s t r i n g
0 1 2 ...             1
                      0</pre>

<p>When you <a href="StringScanner.html#method-i-scan"><code>scan</code></a> for a pattern (a regular expression), the match must occur at the character after the scan pointer.  If you use <a href="StringScanner.html#method-i-scan_until"><code>scan_until</code></a>, then the match can occur anywhere after the scan pointer.  In both cases, the scan pointer moves <em>just beyond</em> the last character of the match, ready to scan again from the next character onwards.  This is demonstrated by the example above.</p>

<h2 id="class-StringScanner-label-Method+Categories">Method Categories<span><a href="#class-StringScanner-label-Method+Categories">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>There are other methods besides the plain scanners.  You can look ahead in the string without actually scanning.  You can access the most recent match. You can modify the string being scanned, reset or terminate the scanner, find out or change the position of the scan pointer, skip ahead, and so on.</p>

<h3 id="class-StringScanner-label-Advancing+the+Scan+Pointer">Advancing the Scan Pointer<span><a href="#class-StringScanner-label-Advancing+the+Scan+Pointer">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="StringScanner.html#method-i-getch"><code>getch</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-get_byte"><code>get_byte</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-scan"><code>scan</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-scan_until"><code>scan_until</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-skip"><code>skip</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-skip_until"><code>skip_until</code></a></p>
</li></ul>

<h3 id="class-StringScanner-label-Looking+Ahead">Looking Ahead<span><a href="#class-StringScanner-label-Looking+Ahead">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="StringScanner.html#method-i-check"><code>check</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-check_until"><code>check_until</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-exist-3F"><code>exist?</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-match-3F"><code>match?</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-peek"><code>peek</code></a></p>
</li></ul>

<h3 id="class-StringScanner-label-Finding+Where+we+Are">Finding Where we Are<span><a href="#class-StringScanner-label-Finding+Where+we+Are">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="StringScanner.html#method-i-beginning_of_line-3F"><code>beginning_of_line?</code></a> (<code>#bol?</code>)</p>
</li><li>
<p><a href="StringScanner.html#method-i-eos-3F"><code>eos?</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-rest-3F"><code>rest?</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-rest_size"><code>rest_size</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-pos"><code>pos</code></a></p>
</li></ul>

<h3 id="class-StringScanner-label-Setting+Where+we+Are">Setting Where we Are<span><a href="#class-StringScanner-label-Setting+Where+we+Are">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="StringScanner.html#method-i-reset"><code>reset</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-terminate"><code>terminate</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-pos-3D"><code>pos=</code></a></p>
</li></ul>

<h3 id="class-StringScanner-label-Match+Data">Match Data<span><a href="#class-StringScanner-label-Match+Data">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="StringScanner.html#method-i-matched"><code>matched</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-matched-3F"><code>matched?</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-matched_size"><code>matched_size</code></a></p>
</li><li>
<p><code>#[]</code></p>
</li><li>
<p><a href="StringScanner.html#method-i-pre_match"><code>pre_match</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-post_match"><code>post_match</code></a></p>
</li></ul>

<h3 id="class-StringScanner-label-Miscellaneous">Miscellaneous<span><a href="#class-StringScanner-label-Miscellaneous">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><code>&lt;&lt;</code></p>
</li><li>
<p><a href="StringScanner.html#method-i-concat"><code>concat</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-string"><code>string</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-string-3D"><code>string=</code></a></p>
</li><li>
<p><a href="StringScanner.html#method-i-unscan"><code>unscan</code></a></p>
</li></ul>

<p>There are aliases to several of the methods.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-must_C_version" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          must_C_version
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>This method is defined for backward compatibility.</p>

                              <div class="method-source-code" id="must_C_version-source">
            <pre>static VALUE
strscan_s_mustc(VALUE self)
{
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(string, fixed_anchor: false)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(string, dup = false)
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new <a href="StringScanner.html"><code>StringScanner</code></a> object to scan over the given <code>string</code>.</p>

<p>If <code>fixed_anchor</code> is <code>true</code>, <code>\A</code> always matches the beginning of the string. Otherwise, <code>\A</code> always matches the current position.</p>

<p><code>dup</code> argument is obsolete and not used now.</p>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
strscan_initialize(int argc, VALUE *argv, VALUE self)
{
    struct strscanner *p;
    VALUE str, options;

    p = check_strscan(self);
    rb_scan_args(argc, argv, &quot;11&quot;, &amp;str, &amp;options);
    options = rb_check_hash_type(options);
    if (!NIL_P(options)) {
        VALUE fixed_anchor;
        ID keyword_ids[1];
        keyword_ids[0] = rb_intern(&quot;fixed_anchor&quot;);
        rb_get_kwargs(options, keyword_ids, 0, 1, &amp;fixed_anchor);
        if (fixed_anchor == Qundef) {
            p-&gt;fixed_anchor_p = false;
        }
        else {
            p-&gt;fixed_anchor_p = RTEST(fixed_anchor);
        }
    }
    else {
        p-&gt;fixed_anchor_p = false;
    }
    StringValue(str);
    p-&gt;str = str;

    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-3C-3C" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          &lt;&lt;(str)
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Appends <code>str</code> to the string being scanned. This method does not affect scan pointer.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/Fri /</span>)
<span class="ruby-identifier">s</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot; +1000 GMT&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">string</span>            <span class="ruby-comment"># -&gt; &quot;Fri Dec 12 1975 14:39 +1000 GMT&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/Dec/</span>)       <span class="ruby-comment"># -&gt; &quot;Dec&quot;</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="StringScanner.html#method-i-concat">concat</a>
                            </div>
                          </div>

                  <div id="method-i-5B-5D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          [](n)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the n-th subgroup in the most recent match.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(\w+) (\w+) (\d+) /</span>)       <span class="ruby-comment"># -&gt; &quot;Fri Dec 12 &quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">0</span>]                               <span class="ruby-comment"># -&gt; &quot;Fri Dec 12 &quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">1</span>]                               <span class="ruby-comment"># -&gt; &quot;Fri&quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">2</span>]                               <span class="ruby-comment"># -&gt; &quot;Dec&quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">3</span>]                               <span class="ruby-comment"># -&gt; &quot;12&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">post_match</span>                       <span class="ruby-comment"># -&gt; &quot;1975 14:39&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pre_match</span>                        <span class="ruby-comment"># -&gt; &quot;&quot;</span>

<span class="ruby-identifier">s</span>.<span class="ruby-identifier">reset</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(?&lt;wday&gt;\w+) (?&lt;month&gt;\w+) (?&lt;day&gt;\d+) /</span>)       <span class="ruby-comment"># -&gt; &quot;Fri Dec 12 &quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">0</span>]                               <span class="ruby-comment"># -&gt; &quot;Fri Dec 12 &quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">1</span>]                               <span class="ruby-comment"># -&gt; &quot;Fri&quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">2</span>]                               <span class="ruby-comment"># -&gt; &quot;Dec&quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">3</span>]                               <span class="ruby-comment"># -&gt; &quot;12&quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">:wday</span>]                           <span class="ruby-comment"># -&gt; &quot;Fri&quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">:month</span>]                          <span class="ruby-comment"># -&gt; &quot;Dec&quot;</span>
<span class="ruby-identifier">s</span>[<span class="ruby-value">:day</span>]                            <span class="ruby-comment"># -&gt; &quot;12&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">post_match</span>                       <span class="ruby-comment"># -&gt; &quot;1975 14:39&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pre_match</span>                        <span class="ruby-comment"># -&gt; &quot;&quot;</span>
</pre>

                              <div class="method-source-code" id="5B-5D-source">
            <pre>static VALUE
strscan_aref(VALUE self, VALUE idx)
{
    const char *name;
    struct strscanner *p;
    long i;

    GET_SCANNER(self, p);
    if (! MATCHED_P(p))        return Qnil;

    switch (TYPE(idx)) {
        case T_SYMBOL:
            idx = rb_sym2str(idx);
            /* fall through */
        case T_STRING:
            if (!RTEST(p-&gt;regex)) return Qnil;
            RSTRING_GETMEM(idx, name, i);
            i = name_to_backref_number(&amp;(p-&gt;regs), p-&gt;regex, name, name + i, rb_enc_get(idx));
            break;
        default:
            i = NUM2LONG(idx);
    }

    if (i &lt; 0)
        i += p-&gt;regs.num_regs;
    if (i &lt; 0)                 return Qnil;
    if (i &gt;= p-&gt;regs.num_regs) return Qnil;
    if (p-&gt;regs.beg[i] == -1)  return Qnil;

    return extract_range(p,
                         adjust_register_position(p, p-&gt;regs.beg[i]),
                         adjust_register_position(p, p-&gt;regs.end[i]));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-beginning_of_line-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">beginning_of_line?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if and only if the scan pointer is at the beginning of the line.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;test\ntest\n&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">bol?</span>           <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/te/</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">bol?</span>           <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/st\n/</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">bol?</span>           <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">terminate</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">bol?</span>           <span class="ruby-comment"># =&gt; true</span>
</pre>

                              <div class="method-source-code" id="beginning_of_line-3F-source">
            <pre>static VALUE
strscan_bol_p(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    if (CURPTR(p) &gt; S_PEND(p)) return Qnil;
    if (p-&gt;curr == 0) return Qtrue;
    return (*(CURPTR(p) - 1) == &#39;\n&#39;) ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-captures" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          captures
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the subgroups in the most recent match (not including the full match). If nothing was priorly matched, it returns nil.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(\w+) (\w+) (\d+) /</span>)       <span class="ruby-comment"># -&gt; &quot;Fri Dec 12 &quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">captures</span>                         <span class="ruby-comment"># -&gt; [&quot;Fri&quot;, &quot;Dec&quot;, &quot;12&quot;]</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(\w+) (\w+) (\d+) /</span>)       <span class="ruby-comment"># -&gt; nil</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">captures</span>                         <span class="ruby-comment"># -&gt; nil</span>
</pre>

                              <div class="method-source-code" id="captures-source">
            <pre>static VALUE
strscan_captures(VALUE self)
{
    struct strscanner *p;
    int   i, num_regs;
    VALUE new_ary;

    GET_SCANNER(self, p);
    if (! MATCHED_P(p))        return Qnil;

    num_regs = p-&gt;regs.num_regs;
    new_ary  = rb_ary_new2(num_regs);

    for (i = 1; i &lt; num_regs; i++) {
        VALUE str = extract_range(p,
                                  adjust_register_position(p, p-&gt;regs.beg[i]),
                                  adjust_register_position(p, p-&gt;regs.end[i]));
        rb_ary_push(new_ary, str);
    }

    return new_ary;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-charpos" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">charpos</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the character position of the scan pointer.  In the ‘reset’ position, this value is zero.  In the ‘terminated’ position (i.e. the string is exhausted), this value is the size of the string.</p>

<p>In short, it’s a 0-based index into the string.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;abc\u00e4def\u00f6ghi&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">charpos</span>                <span class="ruby-comment"># -&gt; 0</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan_until</span>(<span class="ruby-regexp">/\u00e4/</span>)   <span class="ruby-comment"># -&gt; &quot;abc\u00E4&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span>                    <span class="ruby-comment"># -&gt; 5</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">charpos</span>                <span class="ruby-comment"># -&gt; 4</span>
</pre>

                              <div class="method-source-code" id="charpos-source">
            <pre>static VALUE
strscan_get_charpos(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);

    return LONG2NUM(rb_enc_strlen(S_PBEG(p), CURPTR(p), rb_enc_get(p-&gt;str)));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-check" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          check(pattern)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>This returns the value that <a href="StringScanner.html#method-i-scan"><code>scan</code></a> would return, without advancing the scan pointer.  The match register is affected, though.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">check</span> <span class="ruby-regexp">/Fri/</span>               <span class="ruby-comment"># -&gt; &quot;Fri&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span>                       <span class="ruby-comment"># -&gt; 0</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">matched</span>                   <span class="ruby-comment"># -&gt; &quot;Fri&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">check</span> <span class="ruby-regexp">/12/</span>                <span class="ruby-comment"># -&gt; nil</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">matched</span>                   <span class="ruby-comment"># -&gt; nil</span>
</pre>

<p>Mnemonic: it “checks” to see whether a <a href="StringScanner.html#method-i-scan"><code>scan</code></a> will return a value.</p>

                              <div class="method-source-code" id="check-source">
            <pre>static VALUE
strscan_check(VALUE self, VALUE re)
{
    return strscan_do_scan(self, re, 0, 1, 1);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-check_until" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          check_until(pattern)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>This returns the value that <a href="StringScanner.html#method-i-scan_until"><code>scan_until</code></a> would return, without advancing the scan pointer.  The match register is affected, though.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">check_until</span> <span class="ruby-regexp">/12/</span>          <span class="ruby-comment"># -&gt; &quot;Fri Dec 12&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span>                       <span class="ruby-comment"># -&gt; 0</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">matched</span>                   <span class="ruby-comment"># -&gt; 12</span>
</pre>

<p>Mnemonic: it “checks” to see whether a <a href="StringScanner.html#method-i-scan_until"><code>scan_until</code></a> will return a value.</p>

                              <div class="method-source-code" id="check_until-source">
            <pre>static VALUE
strscan_check_until(VALUE self, VALUE re)
{
    return strscan_do_scan(self, re, 0, 1, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-clear" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">clear</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Equivalent to <a href="StringScanner.html#method-i-terminate"><code>terminate</code></a>. This method is obsolete; use <a href="StringScanner.html#method-i-terminate"><code>terminate</code></a> instead.</p>

                              <div class="method-source-code" id="clear-source">
            <pre>static VALUE
strscan_clear(VALUE self)
{
    rb_warning(&quot;StringScanner#clear is obsolete; use #terminate instead&quot;);
    return strscan_terminate(self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-concat" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          concat(str)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Appends <code>str</code> to the string being scanned. This method does not affect scan pointer.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/Fri /</span>)
<span class="ruby-identifier">s</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot; +1000 GMT&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">string</span>            <span class="ruby-comment"># -&gt; &quot;Fri Dec 12 1975 14:39 +1000 GMT&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/Dec/</span>)       <span class="ruby-comment"># -&gt; &quot;Dec&quot;</span>
</pre>

                              <div class="method-source-code" id="concat-source">
            <pre>static VALUE
strscan_concat(VALUE self, VALUE str)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    StringValue(str);
    rb_str_append(p-&gt;str, str);
    return self;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="StringScanner.html#method-i-3C-3C">&lt;&lt;</a>
                            </div>

                          </div>

                  <div id="method-i-empty-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">empty?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Equivalent to <a href="StringScanner.html#method-i-eos-3F"><code>eos?</code></a>. This method is obsolete, use <a href="StringScanner.html#method-i-eos-3F"><code>eos?</code></a> instead.</p>

                              <div class="method-source-code" id="empty-3F-source">
            <pre>static VALUE
strscan_empty_p(VALUE self)
{
    rb_warning(&quot;StringScanner#empty? is obsolete; use #eos? instead&quot;);
    return strscan_eos_p(self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-eos-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">eos?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the scan pointer is at the end of the string.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">eos?</span>          <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/test/</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">eos?</span>          <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">terminate</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">eos?</span>          <span class="ruby-comment"># =&gt; true</span>
</pre>

                              <div class="method-source-code" id="eos-3F-source">
            <pre>static VALUE
strscan_eos_p(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    return EOS_P(p) ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-exist-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          exist?(pattern)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Looks <em>ahead</em> to see if the <code>pattern</code> exists <em>anywhere</em> in the string, without advancing the scan pointer.  This predicates whether a <a href="StringScanner.html#method-i-scan_until"><code>scan_until</code></a> will return a value.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-regexp">/s/</span>            <span class="ruby-comment"># -&gt; 3</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span> <span class="ruby-regexp">/test/</span>           <span class="ruby-comment"># -&gt; &quot;test&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-regexp">/s/</span>            <span class="ruby-comment"># -&gt; 2</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-regexp">/e/</span>            <span class="ruby-comment"># -&gt; nil</span>
</pre>

                              <div class="method-source-code" id="exist-3F-source">
            <pre>static VALUE
strscan_exist_p(VALUE self, VALUE re)
{
    return strscan_do_scan(self, re, 0, 0, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fixed_anchor-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          fixed_anchor? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Whether <code>scanner</code> uses fixed anchor mode or not.</p>

<p>If fixed anchor mode is used, <code>\A</code> always matches the beginning of the string. Otherwise, <code>\A</code> always matches the current position.</p>

                              <div class="method-source-code" id="fixed_anchor-3F-source">
            <pre>static VALUE
strscan_fixed_anchor_p(VALUE self)
{
    struct strscanner *p;
    p = check_strscan(self);
    return p-&gt;fixed_anchor_p ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-get_byte" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">get_byte</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Scans one byte and returns it. This method is not multibyte character sensitive. See also: <a href="StringScanner.html#method-i-getch"><code>getch</code></a>.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;ab&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">get_byte</span>         <span class="ruby-comment"># =&gt; &quot;a&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">get_byte</span>         <span class="ruby-comment"># =&gt; &quot;b&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">get_byte</span>         <span class="ruby-comment"># =&gt; nil</span>

<span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;\244\242&quot;</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&quot;euc-jp&quot;</span>))
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">get_byte</span>         <span class="ruby-comment"># =&gt; &quot;\xA4&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">get_byte</span>         <span class="ruby-comment"># =&gt; &quot;\xA2&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">get_byte</span>         <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="get_byte-source">
            <pre>static VALUE
strscan_get_byte(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    CLEAR_MATCH_STATUS(p);
    if (EOS_P(p))
        return Qnil;

    p-&gt;prev = p-&gt;curr;
    p-&gt;curr++;
    MATCHED(p);
    adjust_registers_to_matched(p);
    return extract_range(p,
                         adjust_register_position(p, p-&gt;regs.beg[0]),
                         adjust_register_position(p, p-&gt;regs.end[0]));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-getbyte" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">getbyte</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Equivalent to <a href="StringScanner.html#method-i-get_byte"><code>get_byte</code></a>. This method is obsolete; use <a href="StringScanner.html#method-i-get_byte"><code>get_byte</code></a> instead.</p>

                              <div class="method-source-code" id="getbyte-source">
            <pre>static VALUE
strscan_getbyte(VALUE self)
{
    rb_warning(&quot;StringScanner#getbyte is obsolete; use #get_byte instead&quot;);
    return strscan_get_byte(self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-getch" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">getch</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Scans one character and returns it. This method is multibyte character sensitive.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;ab&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">getch</span>           <span class="ruby-comment"># =&gt; &quot;a&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">getch</span>           <span class="ruby-comment"># =&gt; &quot;b&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">getch</span>           <span class="ruby-comment"># =&gt; nil</span>

<span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;\244\242&quot;</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&quot;euc-jp&quot;</span>))
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">getch</span>           <span class="ruby-comment"># =&gt; &quot;\x{A4A2}&quot;   # Japanese hira-kana &quot;A&quot; in EUC-JP</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">getch</span>           <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="getch-source">
            <pre>static VALUE
strscan_getch(VALUE self)
{
    struct strscanner *p;
    long len;

    GET_SCANNER(self, p);
    CLEAR_MATCH_STATUS(p);
    if (EOS_P(p))
        return Qnil;

    len = rb_enc_mbclen(CURPTR(p), S_PEND(p), rb_enc_get(p-&gt;str));
    len = minl(len, S_RESTLEN(p));
    p-&gt;prev = p-&gt;curr;
    p-&gt;curr += len;
    MATCHED(p);
    adjust_registers_to_matched(p);
    return extract_range(p,
                         adjust_register_position(p, p-&gt;regs.beg[0]),
                         adjust_register_position(p, p-&gt;regs.end[0]));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string that represents the <a href="StringScanner.html"><code>StringScanner</code></a> object, showing:</p>
<ul><li>
<p>the current position</p>
</li><li>
<p>the size of the string</p>
</li><li>
<p>the characters surrounding the scan pointer</p>

<p>s = <a href="StringScanner.html#method-c-new"><code>StringScanner.new</code></a>(“Fri Dec 12 1975 14:39”) s.inspect            # -&gt; ‘#&lt;StringScanner 0/21 @ “Fri D…”&gt;’ s.scan_until /12/    # -&gt; “Fri Dec 12” s.inspect            # -&gt; ‘#&lt;StringScanner 10/21 “…ec 12” @ “ 1975…”&gt;’</p>
</li></ul>

                              <div class="method-source-code" id="inspect-source">
            <pre>static VALUE
strscan_inspect(VALUE self)
{
    struct strscanner *p;
    VALUE a, b;

    p = check_strscan(self);
    if (NIL_P(p-&gt;str)) {
        a = rb_sprintf(&quot;#&lt;%&quot;PRIsVALUE&quot; (uninitialized)&gt;&quot;, rb_obj_class(self));
        return a;
    }
    if (EOS_P(p)) {
        a = rb_sprintf(&quot;#&lt;%&quot;PRIsVALUE&quot; fin&gt;&quot;, rb_obj_class(self));
        return a;
    }
    if (p-&gt;curr == 0) {
        b = inspect2(p);
        a = rb_sprintf(&quot;#&lt;%&quot;PRIsVALUE&quot; %ld/%ld @ %&quot;PRIsVALUE&quot;&gt;&quot;,
                       rb_obj_class(self),
                       p-&gt;curr, S_LEN(p),
                       b);
        return a;
    }
    a = inspect1(p);
    b = inspect2(p);
    a = rb_sprintf(&quot;#&lt;%&quot;PRIsVALUE&quot; %ld/%ld %&quot;PRIsVALUE&quot; @ %&quot;PRIsVALUE&quot;&gt;&quot;,
                   rb_obj_class(self),
                   p-&gt;curr, S_LEN(p),
                   a, b);
    return a;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-match-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          match?(pattern)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Tests whether the given <code>pattern</code> is matched from the current scan pointer. Returns the length of the match, or <code>nil</code>.  The scan pointer is not advanced.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/\w+/</span>)   <span class="ruby-comment"># -&gt; 4</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/\w+/</span>)   <span class="ruby-comment"># -&gt; 4</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-string">&quot;test&quot;</span>)  <span class="ruby-comment"># -&gt; 4</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/\s+/</span>)   <span class="ruby-comment"># -&gt; nil</span>
</pre>

                              <div class="method-source-code" id="match-3F-source">
            <pre>static VALUE
strscan_match_p(VALUE self, VALUE re)
{
    return strscan_do_scan(self, re, 0, 0, 1);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-matched" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">matched</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the last matched string.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/\w+/</span>)     <span class="ruby-comment"># -&gt; 4</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">matched</span>           <span class="ruby-comment"># -&gt; &quot;test&quot;</span>
</pre>

                              <div class="method-source-code" id="matched-source">
            <pre>static VALUE
strscan_matched(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    if (! MATCHED_P(p)) return Qnil;
    return extract_range(p,
                         adjust_register_position(p, p-&gt;regs.beg[0]),
                         adjust_register_position(p, p-&gt;regs.end[0]));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-matched-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">matched?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if and only if the last match was successful.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/\w+/</span>)     <span class="ruby-comment"># =&gt; 4</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">matched?</span>          <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/\d+/</span>)     <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">matched?</span>          <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="matched-3F-source">
            <pre>static VALUE
strscan_matched_p(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    return MATCHED_P(p) ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-matched_size" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">matched_size</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the size of the most recent match in bytes, or <code>nil</code> if there was no recent match.  This is different than <code>matched.size</code>, which will return the size in characters.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">check</span> <span class="ruby-regexp">/\w+/</span>           <span class="ruby-comment"># -&gt; &quot;test&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">matched_size</span>          <span class="ruby-comment"># -&gt; 4</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">check</span> <span class="ruby-regexp">/\d+/</span>           <span class="ruby-comment"># -&gt; nil</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">matched_size</span>          <span class="ruby-comment"># -&gt; nil</span>
</pre>

                              <div class="method-source-code" id="matched_size-source">
            <pre>static VALUE
strscan_matched_size(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    if (! MATCHED_P(p)) return Qnil;
    return LONG2NUM(p-&gt;regs.end[0] - p-&gt;regs.beg[0]);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-named_captures" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          named_captures &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a hash of string variables matching the regular expression.</p>

<pre class="ruby"><span class="ruby-identifier">scan</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foobarbaz&#39;</span>)
<span class="ruby-identifier">scan</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/(?&lt;f&gt;foo)(?&lt;r&gt;bar)(?&lt;z&gt;baz)/</span>)
<span class="ruby-identifier">scan</span>.<span class="ruby-identifier">named_captures</span> <span class="ruby-comment"># -&gt; {&quot;f&quot;=&gt;&quot;foo&quot;, &quot;r&quot;=&gt;&quot;bar&quot;, &quot;z&quot;=&gt;&quot;baz&quot;}</span>
</pre>

                              <div class="method-source-code" id="named_captures-source">
            <pre>static VALUE
strscan_named_captures(VALUE self)
{
    struct strscanner *p;
    GET_SCANNER(self, p);
    named_captures_data data;
    data.self = self;
    data.captures = rb_hash_new();
    if (!RB_NIL_P(p-&gt;regex)) {
        onig_foreach_name(RREGEXP_PTR(p-&gt;regex), named_captures_iter, &amp;data);
    }

    return data.captures;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-peek" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          peek(len)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Extracts a string corresponding to <code>string[pos,len]</code>, without advancing the scan pointer.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">peek</span>(<span class="ruby-value">7</span>)          <span class="ruby-comment"># =&gt; &quot;test st&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">peek</span>(<span class="ruby-value">7</span>)          <span class="ruby-comment"># =&gt; &quot;test st&quot;</span>
</pre>

                              <div class="method-source-code" id="peek-source">
            <pre>static VALUE
strscan_peek(VALUE self, VALUE vlen)
{
    struct strscanner *p;
    long len;

    GET_SCANNER(self, p);

    len = NUM2LONG(vlen);
    if (EOS_P(p))
        return str_new(p, &quot;&quot;, 0);

    len = minl(len, S_RESTLEN(p));
    return extract_beg_len(p, p-&gt;curr, len);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-peep" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">peep</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Equivalent to <a href="StringScanner.html#method-i-peek"><code>peek</code></a>. This method is obsolete; use <a href="StringScanner.html#method-i-peek"><code>peek</code></a> instead.</p>

                              <div class="method-source-code" id="peep-source">
            <pre>static VALUE
strscan_peep(VALUE self, VALUE vlen)
{
    rb_warning(&quot;StringScanner#peep is obsolete; use #peek instead&quot;);
    return strscan_peek(self, vlen);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-pointer" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">pointer</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the byte position of the scan pointer.  In the ‘reset’ position, this value is zero.  In the ‘terminated’ position (i.e. the string is exhausted), this value is the bytesize of the string.</p>

<p>In short, it’s a 0-based index into bytes of the string.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span>               <span class="ruby-comment"># -&gt; 0</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan_until</span> <span class="ruby-regexp">/str/</span>  <span class="ruby-comment"># -&gt; &quot;test str&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span>               <span class="ruby-comment"># -&gt; 8</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">terminate</span>         <span class="ruby-comment"># -&gt; #&lt;StringScanner fin&gt;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span>               <span class="ruby-comment"># -&gt; 11</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="StringScanner.html#method-i-pos">pos</a>
                            </div>
                          </div>

                  <div id="method-i-pointer-3D" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">pointer=</span><span
                                class="method-args">(p1)</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the byte position of the scan pointer.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">7</span>            <span class="ruby-comment"># -&gt; 7</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">rest</span>               <span class="ruby-comment"># -&gt; &quot;ring&quot;</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="StringScanner.html#method-i-pos-3D">pos=</a>
                            </div>
                          </div>

                  <div id="method-i-pos" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">pos</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the byte position of the scan pointer.  In the ‘reset’ position, this value is zero.  In the ‘terminated’ position (i.e. the string is exhausted), this value is the bytesize of the string.</p>

<p>In short, it’s a 0-based index into bytes of the string.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span>               <span class="ruby-comment"># -&gt; 0</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan_until</span> <span class="ruby-regexp">/str/</span>  <span class="ruby-comment"># -&gt; &quot;test str&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span>               <span class="ruby-comment"># -&gt; 8</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">terminate</span>         <span class="ruby-comment"># -&gt; #&lt;StringScanner fin&gt;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span>               <span class="ruby-comment"># -&gt; 11</span>
</pre>

                              <div class="method-source-code" id="pos-source">
            <pre>static VALUE
strscan_get_pos(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    return INT2FIX(p-&gt;curr);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="StringScanner.html#method-i-pointer">pointer</a>
                            </div>

                          </div>

                  <div id="method-i-pos-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          pos=(n)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the byte position of the scan pointer.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">7</span>            <span class="ruby-comment"># -&gt; 7</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">rest</span>               <span class="ruby-comment"># -&gt; &quot;ring&quot;</span>
</pre>

                              <div class="method-source-code" id="pos-3D-source">
            <pre>static VALUE
strscan_set_pos(VALUE self, VALUE v)
{
    struct strscanner *p;
    long i;

    GET_SCANNER(self, p);
    i = NUM2INT(v);
    if (i &lt; 0) i += S_LEN(p);
    if (i &lt; 0) rb_raise(rb_eRangeError, &quot;index out of range&quot;);
    if (i &gt; S_LEN(p)) rb_raise(rb_eRangeError, &quot;index out of range&quot;);
    p-&gt;curr = i;
    return LONG2NUM(i);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="StringScanner.html#method-i-pointer-3D">pointer=</a>
                            </div>

                          </div>

                  <div id="method-i-post_match" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">post_match</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the <strong><em>post</strong>-match</em> (in the regular expression sense) of the last scan.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)           <span class="ruby-comment"># -&gt; &quot;test&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\s+/</span>)           <span class="ruby-comment"># -&gt; &quot; &quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pre_match</span>             <span class="ruby-comment"># -&gt; &quot;test&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">post_match</span>            <span class="ruby-comment"># -&gt; &quot;string&quot;</span>
</pre>

                              <div class="method-source-code" id="post_match-source">
            <pre>static VALUE
strscan_post_match(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    if (! MATCHED_P(p)) return Qnil;
    return extract_range(p,
                         adjust_register_position(p, p-&gt;regs.end[0]),
                         S_LEN(p));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-pre_match" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">pre_match</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the <strong><em>pre</strong>-match</em> (in the regular expression sense) of the last scan.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)           <span class="ruby-comment"># -&gt; &quot;test&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\s+/</span>)           <span class="ruby-comment"># -&gt; &quot; &quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pre_match</span>             <span class="ruby-comment"># -&gt; &quot;test&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">post_match</span>            <span class="ruby-comment"># -&gt; &quot;string&quot;</span>
</pre>

                              <div class="method-source-code" id="pre_match-source">
            <pre>static VALUE
strscan_pre_match(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    if (! MATCHED_P(p)) return Qnil;
    return extract_range(p,
                         0,
                         adjust_register_position(p, p-&gt;regs.beg[0]));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-reset" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">reset</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Reset the scan pointer (index 0) and clear matching data.</p>

                              <div class="method-source-code" id="reset-source">
            <pre>static VALUE
strscan_reset(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    p-&gt;curr = 0;
    CLEAR_MATCH_STATUS(p);
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rest" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rest</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the “rest” of the string (i.e. everything after the scan pointer). If there is no more data (eos? = true), it returns <code>&quot;&quot;</code>.</p>

                              <div class="method-source-code" id="rest-source">
            <pre>static VALUE
strscan_rest(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    if (EOS_P(p)) {
        return str_new(p, &quot;&quot;, 0);
    }
    return extract_range(p, p-&gt;curr, S_LEN(p));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rest-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rest?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if and only if there is more data in the string.  See <a href="StringScanner.html#method-i-eos-3F"><code>eos?</code></a>. This method is obsolete; use <a href="StringScanner.html#method-i-eos-3F"><code>eos?</code></a> instead.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-comment"># These two are opposites</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">eos?</span> <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">rest?</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

                              <div class="method-source-code" id="rest-3F-source">
            <pre>static VALUE
strscan_rest_p(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    return EOS_P(p) ? Qfalse : Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rest_size" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rest_size</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><code>s.rest_size</code> is equivalent to <code>s.rest.size</code>.</p>

                              <div class="method-source-code" id="rest_size-source">
            <pre>static VALUE
strscan_rest_size(VALUE self)
{
    struct strscanner *p;
    long i;

    GET_SCANNER(self, p);
    if (EOS_P(p)) {
        return INT2FIX(0);
    }
    i = S_RESTLEN(p);
    return INT2FIX(i);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-restsize" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">restsize</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><code>s.restsize</code> is equivalent to <code>s.rest_size</code>. This method is obsolete; use <a href="StringScanner.html#method-i-rest_size"><code>rest_size</code></a> instead.</p>

                              <div class="method-source-code" id="restsize-source">
            <pre>static VALUE
strscan_restsize(VALUE self)
{
    rb_warning(&quot;StringScanner#restsize is obsolete; use #rest_size instead&quot;);
    return strscan_rest_size(self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-scan" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          scan(pattern) &rarr; String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Tries to match with <code>pattern</code> at the current position. If there’s a match, the scanner advances the “scan pointer” and returns the matched string. Otherwise, the scanner returns <code>nil</code>.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)   <span class="ruby-comment"># -&gt; &quot;test&quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)   <span class="ruby-comment"># -&gt; nil</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\s+/</span>)   <span class="ruby-comment"># -&gt; &quot; &quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-string">&quot;str&quot;</span>)   <span class="ruby-comment"># -&gt; &quot;str&quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)   <span class="ruby-comment"># -&gt; &quot;ing&quot;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/./</span>)     <span class="ruby-comment"># -&gt; nil</span>
</pre>

                              <div class="method-source-code" id="scan-source">
            <pre>static VALUE
strscan_scan(VALUE self, VALUE re)
{
    return strscan_do_scan(self, re, 1, 1, 1);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-scan_full" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          scan_full(pattern, advance_pointer_p, return_string_p)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Tests whether the given <code>pattern</code> is matched from the current scan pointer. Advances the scan pointer if <code>advance_pointer_p</code> is true. Returns the matched string if <code>return_string_p</code> is true. The match register is affected.</p>

<p>“full” means “#scan with full parameters”.</p>

                              <div class="method-source-code" id="scan_full-source">
            <pre>static VALUE
strscan_scan_full(VALUE self, VALUE re, VALUE s, VALUE f)
{
    return strscan_do_scan(self, re, RTEST(s), RTEST(f), 1);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-scan_until" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          scan_until(pattern)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Scans the string <em>until</em> the <code>pattern</code> is matched.  Returns the substring up to and including the end of the match, advancing the scan pointer to that location. If there is no match, <code>nil</code> is returned.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan_until</span>(<span class="ruby-regexp">/1/</span>)        <span class="ruby-comment"># -&gt; &quot;Fri Dec 1&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">pre_match</span>              <span class="ruby-comment"># -&gt; &quot;Fri Dec &quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan_until</span>(<span class="ruby-regexp">/XYZ/</span>)      <span class="ruby-comment"># -&gt; nil</span>
</pre>

                              <div class="method-source-code" id="scan_until-source">
            <pre>static VALUE
strscan_scan_until(VALUE self, VALUE re)
{
    return strscan_do_scan(self, re, 1, 1, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-search_full" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          search_full(pattern, advance_pointer_p, return_string_p)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Scans the string <em>until</em> the <code>pattern</code> is matched. Advances the scan pointer if <code>advance_pointer_p</code>, otherwise not. Returns the matched string if <code>return_string_p</code> is true, otherwise returns the number of bytes advanced. This method does affect the match register.</p>

                              <div class="method-source-code" id="search_full-source">
            <pre>static VALUE
strscan_search_full(VALUE self, VALUE re, VALUE s, VALUE f)
{
    return strscan_do_scan(self, re, RTEST(s), RTEST(f), 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-size" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          size
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the amount of subgroups in the most recent match. The full match counts as a subgroup.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(\w+) (\w+) (\d+) /</span>)       <span class="ruby-comment"># -&gt; &quot;Fri Dec 12 &quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">size</span>                             <span class="ruby-comment"># -&gt; 4</span>
</pre>

                              <div class="method-source-code" id="size-source">
            <pre>static VALUE
strscan_size(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    if (! MATCHED_P(p))        return Qnil;
    return INT2FIX(p-&gt;regs.num_regs);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-skip" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          skip(pattern)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Attempts to skip over the given <code>pattern</code> beginning with the scan pointer. If it matches, the scan pointer is advanced to the end of the match, and the length of the match is returned.  Otherwise, <code>nil</code> is returned.</p>

<p>It’s similar to <a href="StringScanner.html#method-i-scan"><code>scan</code></a>, but without returning the matched string.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">skip</span>(<span class="ruby-regexp">/\w+/</span>)   <span class="ruby-comment"># -&gt; 4</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">skip</span>(<span class="ruby-regexp">/\w+/</span>)   <span class="ruby-comment"># -&gt; nil</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">skip</span>(<span class="ruby-regexp">/\s+/</span>)   <span class="ruby-comment"># -&gt; 1</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">skip</span>(<span class="ruby-string">&quot;st&quot;</span>)    <span class="ruby-comment"># -&gt; 2</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">skip</span>(<span class="ruby-regexp">/\w+/</span>)   <span class="ruby-comment"># -&gt; 4</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">skip</span>(<span class="ruby-regexp">/./</span>)     <span class="ruby-comment"># -&gt; nil</span>
</pre>

                              <div class="method-source-code" id="skip-source">
            <pre>static VALUE
strscan_skip(VALUE self, VALUE re)
{
    return strscan_do_scan(self, re, 1, 0, 1);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-skip_until" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          skip_until(pattern)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Advances the scan pointer until <code>pattern</code> is matched and consumed.  Returns the number of bytes advanced, or <code>nil</code> if no match was found.</p>

<p>Look ahead to match <code>pattern</code>, and advance the scan pointer to the <em>end</em> of the match.  Return the number of characters advanced, or <code>nil</code> if the match was unsuccessful.</p>

<p>It’s similar to <a href="StringScanner.html#method-i-scan_until"><code>scan_until</code></a>, but without returning the intervening string.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">skip_until</span> <span class="ruby-regexp">/12/</span>           <span class="ruby-comment"># -&gt; 10</span>
<span class="ruby-identifier">s</span>                           <span class="ruby-comment">#</span>
</pre>

                              <div class="method-source-code" id="skip_until-source">
            <pre>static VALUE
strscan_skip_until(VALUE self, VALUE re)
{
    return strscan_do_scan(self, re, 1, 0, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-string" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">string</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the string being scanned.</p>

                              <div class="method-source-code" id="string-source">
            <pre>static VALUE
strscan_get_string(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    return p-&gt;str;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-string-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          string=(str)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Changes the string being scanned to <code>str</code> and resets the scanner. Returns <code>str</code>.</p>

                              <div class="method-source-code" id="string-3D-source">
            <pre>static VALUE
strscan_set_string(VALUE self, VALUE str)
{
    struct strscanner *p = check_strscan(self);

    StringValue(str);
    p-&gt;str = str;
    p-&gt;curr = 0;
    CLEAR_MATCH_STATUS(p);
    return str;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-terminate" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          terminate
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          clear
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Sets the scan pointer to the end of the string and clear matching data.</p>

                              <div class="method-source-code" id="terminate-source">
            <pre>static VALUE
strscan_terminate(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    p-&gt;curr = S_LEN(p);
    CLEAR_MATCH_STATUS(p);
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-unscan" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">unscan</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the scan pointer to the previous position.  Only one previous position is remembered, and it changes with each scanning operation.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;test string&#39;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)        <span class="ruby-comment"># =&gt; &quot;test&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">unscan</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/../</span>)         <span class="ruby-comment"># =&gt; &quot;te&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\d/</span>)         <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">unscan</span>             <span class="ruby-comment"># ScanError: unscan failed: previous match record not exist</span>
</pre>

                              <div class="method-source-code" id="unscan-source">
            <pre>static VALUE
strscan_unscan(VALUE self)
{
    struct strscanner *p;

    GET_SCANNER(self, p);
    if (! MATCHED_P(p))
        rb_raise(ScanError, &quot;unscan failed: previous match record not exist&quot;);
    p-&gt;curr = p-&gt;prev;
    CLEAR_MATCH_STATUS(p);
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-values_at" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          values_at( i1, i2, ... iN )   &rarr; an_array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the subgroups in the most recent match at the given indices. If nothing was priorly matched, it returns nil.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Fri Dec 12 1975 14:39&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(\w+) (\w+) (\d+) /</span>)       <span class="ruby-comment"># -&gt; &quot;Fri Dec 12 &quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">values_at</span> <span class="ruby-value">0</span>, <span class="ruby-value">-1</span>, <span class="ruby-value">5</span>, <span class="ruby-value">2</span>            <span class="ruby-comment"># -&gt; [&quot;Fri Dec 12 &quot;, &quot;12&quot;, nil, &quot;Dec&quot;]</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(\w+) (\w+) (\d+) /</span>)       <span class="ruby-comment"># -&gt; nil</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">values_at</span> <span class="ruby-value">0</span>, <span class="ruby-value">-1</span>, <span class="ruby-value">5</span>, <span class="ruby-value">2</span>            <span class="ruby-comment"># -&gt; nil</span>
</pre>

                              <div class="method-source-code" id="values_at-source">
            <pre>static VALUE
strscan_values_at(int argc, VALUE *argv, VALUE self)
{
    struct strscanner *p;
    long i;
    VALUE new_ary;

    GET_SCANNER(self, p);
    if (! MATCHED_P(p))        return Qnil;

    new_ary = rb_ary_new2(argc);
    for (i = 0; i&lt;argc; i++) {
        rb_ary_push(new_ary, strscan_aref(self, argv[i]));
    }

    return new_ary;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-initialize_copy" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dup
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          clone
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Duplicates a <a href="StringScanner.html"><code>StringScanner</code></a> object.</p>

                              <div class="method-source-code" id="initialize_copy-source">
            <pre>static VALUE
strscan_init_copy(VALUE vself, VALUE vorig)
{
    struct strscanner *self, *orig;

    self = check_strscan(vself);
    orig = check_strscan(vorig);
    if (self != orig) {
        self-&gt;flags = orig-&gt;flags;
        self-&gt;str = orig-&gt;str;
        self-&gt;prev = orig-&gt;prev;
        self-&gt;curr = orig-&gt;curr;
        if (rb_reg_region_copy(&amp;self-&gt;regs, &amp;orig-&gt;regs))
            rb_memerror();
        RB_GC_GUARD(vorig);
    }

    return vself;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

